using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;
using System;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UINServerNode : UIBaseNode
    {
        #region Template Generate,don't modify
        protected partial class UIB_UINServerNode
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExButton btn_serverNode { protected set; get; }
            public IQIGame.Onigao.Framework.ExText tex_ServerId { protected set; get; }
            public IQIGame.Onigao.Framework.ExText tex_ServerName { protected set; get; }
            protected virtual void InitBinding(ObjectBinding __binding)
            {
                var __tbv0 = __binding.GetVariableByName("btn_serverNode");
                this.btn_serverNode = __tbv0.GetValue<IQIGame.Onigao.Framework.ExButton>();
                var __tbv1 = __binding.GetVariableByName("tex_ServerId");
                this.tex_ServerId = __tbv1.GetValue<IQIGame.Onigao.Framework.ExText>();
                var __tbv2 = __binding.GetVariableByName("tex_ServerName");
                this.tex_ServerName = __tbv2.GetValue<IQIGame.Onigao.Framework.ExText>();
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        /// <summary>
        /// 可以自定义修改的
        /// </summary>
        protected partial class UIB_UINServerNode
        {
            public virtual void StartBinding(GameObject __go)
            {
                var binding = __go.GetComponent<ObjectBinding>();
                if (binding != null)
                {
                    this.InitBinding(binding);
                }
            }
        }
        protected UIB_UINServerNode ui { get; set; }

        public LoginResponseServerInfo serverInfo;
        private Action<UINServerNode> clickEvent;

        protected override void BeforeInit()
        {
            ui = new UIB_UINServerNode();
            ui.StartBinding(gameObject);
        }

        protected override void OnInit()
        {
            this.ui.btn_serverNode.AddClickEvent(OnBtnSelected);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        public void InitServerInfo(LoginResponseServerInfo serverInfo, Action<UINServerNode> clickEvent)
        {
            this.serverInfo = serverInfo;
            this.clickEvent = clickEvent;

            this.ui.tex_ServerId.text = serverInfo.serverId;
            this.ui.tex_ServerName.text = serverInfo.serverName;
        }

        private void OnBtnSelected()
        {
            this.clickEvent?.Invoke(this);
        }

        protected override void OnDispose()
        {

        }
    }
}
